package com.examsystem.controller;

import com.examsystem.util.UploadImgUtils;
import com.examsystem.service.UploadService;
import com.examsystem.pojo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;


/**
 * @author Administrator
 */
@Controller
@RequestMapping("/upload")
public class UploadController {
    @Autowired
    private UploadService uploadService;

    /**
     * 上传试卷试题答案/解析、教师头像【1：答案  2：解析  3：上传/修改教师头像】
     * @param file  文件
     * @param teacherId  教师id
     * @return result对象
     */
    @PostMapping({"/paperImg"})
    @ResponseBody
    public Result upload(@RequestParam("file") MultipartFile file,int teacherId){
        UploadImgUtils uploadImgUtils = new UploadImgUtils();
        String s = uploadImgUtils.uploadImg(file);
        if (s != null){
            Result result = uploadService.uploadImg(s, teacherId);
            return Result.succ(result);
        }
        return Result.fail("文件上传失败");
    }
}